package com.goods.controller.business;

import com.goods.business.service.ListService;
import com.goods.common.error.BusinessException;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：MJS
 * @date ：Created in 2021/6/8  15:12
 * @description：TODO
 */
@RestController
@RequestMapping("/business/product")
@Api(tags = "业务管理-物资资料")
public class ListController {
    @Autowired
    private ListService listService;

    //查询全部物资 及 模糊查询
    @ApiOperation(value = "物资资料列表", notes = "模糊查询物资资料列表")
    @GetMapping("/findProductList")
    public ResponseBean<PageVO<ProductVO>> findProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                           @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize,
                                                           ProductVO productVO) throws BusinessException {
        //Request URL: http://www.localhost:8989/business/product/findProductList?pageNum=1&pageSize=6&name=%E8%84%91%E7%99%BD%E9%87%91&categoryId=&supplier=&status=0
        PageVO<ProductVO> listServiceProductList = listService.findProductList(pageNum, pageSize, productVO);
        return ResponseBean.success(listServiceProductList);

    }
    //添加物资
    @ApiOperation(value = "物资添加", notes = "添加物资列表")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductVO productVO){
        listService.add(productVO);
        return ResponseBean.success();
    }
    //物资回显
    @ApiOperation(value = "物资回显", notes = "回显物资列表")
    @GetMapping("/edit/{id}")
    public ResponseBean<ProductVO>edit(@PathVariable Long id) throws BusinessException {
        ProductVO productVO=listService.edit(id);
        return ResponseBean.success(productVO);
    }
    //更新物资
    @ApiOperation(value = "更新物资", notes = "更新物资列表")
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,
                               @RequestBody ProductVO productVO){
        listService.update(id,productVO);
        return ResponseBean.success();
    }
    //移入回收站
    @ApiOperation(value = "移入回收站", notes = "数据移入回收站")
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        listService.remove(id);
        return ResponseBean.success();
    }
    //从回收站恢复
    @ApiOperation(value = "从回收站恢复", notes = "数据移出回收站")
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        listService.back(id);
        return ResponseBean.success();
    }
    //删除物资
    @ApiOperation(value = "从回收站删除", notes = "删除物资")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        listService.delete(id);
        return ResponseBean.success();
    }
    //物资审核
    @ApiOperation(value = "物资审核", notes = "物资审核列表")
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        listService.publish(id);
        return ResponseBean.success();
    }
}
